package com.qef.com.mmovie.mvp.interactor;

import com.orhanobut.logger.Logger;
import com.qef.com.mmovie.api.TopVieddoServer;
import com.qef.com.mmovie.entity.VideoPlayEntity;
import com.qef.com.mmovie.entity.VideoTopEntity;
import com.qef.com.mmovie.net.IGetDataDelegate;
import com.qef.com.mmovie.utils.RxUtil;

import java.net.URLEncoder;

import javax.inject.Inject;

import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

import static android.R.attr.data;

/**
 * Created by guangjiego on 2017/3/22.
 */

public class VideoTopInteractor {
    private TopVieddoServer topVieddoServe;

    @Inject
    public VideoTopInteractor(TopVieddoServer topVieddoServer) {
        this.topVieddoServe = topVieddoServer;
    }

    public Disposable loadTopPlayList(int page, final IGetDataDelegate<VideoTopEntity> iGetDataDelegate) {
        return topVieddoServe.getTopVideoList("2", page, "video")
                .compose(RxUtil.<VideoTopEntity>background())
                .subscribe(infoEntity -> iGetDataDelegate.getDataSuccess(infoEntity), new Consumer<Throwable>() {
                            @Override
                            public void accept(@NonNull Throwable throwable) throws Exception {
                                throwable.printStackTrace();
                                iGetDataDelegate.getDataError(throwable);
                            }
                        }
                );
    }

    public Disposable loadVideoPlay(String id, final IGetDataDelegate<VideoPlayEntity> iGetDataDelegate) {
        return topVieddoServe.getVideoPaly(id).compose(RxUtil.background()).subscribe(new Consumer<VideoPlayEntity>() {
            @Override
            public void accept(@NonNull VideoPlayEntity videoPlayEntity) throws Exception {
                iGetDataDelegate.getDataSuccess(videoPlayEntity);
            }

        }, new Consumer<Throwable>() {
            @Override
            public void accept(@NonNull Throwable throwable) throws Exception {
                throwable.printStackTrace();
                iGetDataDelegate.getDataError(throwable);
            }
        });
    }
}
